var prefix = ctx + "toolLedger/directStorage";

$(function() {
	$("#dprtcode").val(window.parent.document.getElementById("dprtcode").value);
	localRefresh();
//	setInterval(localRefresh, 5000); //自动刷新预警信息
	initParentType();				//初始化生工具类型
//    initToolsCabinetId();			//初始化工具柜
    var options = {
        url: prefix + "/list",
        exportUrl: prefix + "/export",
        striped: true,
        search:false,	
        showSearch:false,	
        showRefresh:false,	
        showToggle:false,	
        queryParams: queryParams,
        showColumns:false,	
        modalName: "库存",
      	onLoadSuccess:function(data){
			signByKeyword($("#keyword").val(), [2,3,4,5,7,9]);// 标记关键字
			$.table.onLoadSuccess(data);
        },
        columns: [
		{
		    title: "序号",
		    formatter: function (value, row, index) {
		 	    return $.table.serialNumber(index);
		    }
		},
		{
        	field: 'useCode',
        	title: '<span style="color:red" >*</span>编号',
        	sortable: true,
            formatter: function(value, row, index) {
            	return $.table.tooltip(value);
            }
        },
		 {
        	field: 'toolName',
        	title: '<span style="color:red" >*</span>工具名称',
        	sortable: true,
        	formatter: function(value, row, index) {
        		return $.table.tooltip(value);
        	}
        },
        {
        	field: 'factoryName',
        	title: '<span style="color:red" >*</span>工具厂家',
        	sortable: true,
        	formatter: function(value, row, index) {
        		return $.table.tooltip(value);
        	}
        },
        {
        	field: 'modelName',
        	title: '<span style="color:red" >*</span>规格型号',
        	sortable: true,
            formatter: function(value, row, index) {
            	return $.table.tooltip(value);
            }
        },
        {
        	field: 'elecLevelId',
        	title: '<span style="color:red" >*</span>电压等级',
        	sortable: true,
        	formatter: function (value, row, index) {
        		return $.table.selectDict(voltage_level, value);
        	}
        },
        {
        	 field: 'inoutState',
             title: '在库状态',
             sortable: true,
             formatter: function (value, row, index) {
                 return $.table.selectDict(kf_tools_inout_state, value);
             }
        },
        {
            field: 'testDate',
            title: '试验日期',
            sortable: true,
            formatter: function (value, row, index) {
                return formatUndefine(value).substring(0, 10);
            }
        },
        {
        	field: 'nextTestDate',
        	title: '下次试验日期',
        	sortable: true,
        	 formatter: function (value, row, index) {
                 return formatUndefine(value).substring(0, 10);
             }
        },
        {
        	field: 'isqualified',
        	title: '是否合格',
        	sortable: true,
        	formatter: function (value, row, index) {
              if(value=="1"){
            	  return "合格";
              }else if(value=="2"){
            	  return "不合格";
              }else{
            	  return "未检测";
              }
              
            }
        },
        {
        	field: 'rfid',
        	title: 'RFID',
        	sortable: true
        },
        {
        	field: 'deptName',
        	title: '检测单位',
        	sortable: true
        },
        {
        	field: 'testname',
        	title: '实验人员',
        	sortable: true
        },
        {
        	field: 'avatar',
        	title: '详细报告',
        	sortable: true,
        	formatter: function (value, item, index) {
        		if(value!="" && value!=null){
        			return '<a target="_blank" href="http://www.rui9.net:8084/profile/avatar/'+value+'"><img src="'+ctx+'img/pdf.png"    /></a>';
        		}else{
        			return "-";
        		}
        	}
        },
 
        ]
    };
    $.table.init(options);
});

function queryParams(params) {
    return {
    	dprtcode:$("#dprtcode").val(),
        pageSize: params.limit,
        pageNum: params.offset / params.limit + 1,
        searchValue: params.search,
        orderByColumn: params.sort,
        isAsc: params.order
    };
}


/**
 * 初始化工具类型
 */
function initParentType(){
	
	$.ajax({
		cache : true,
		type : "POST",
		url : ctx + "basicData/toolsType/initParentType",
		async : false,
		data :{'dprtcode' : $("#dprtcode").val()},
		error : function(request) {
			$.modal.alertError("系统错误");
		},
		success : function(data) {
			 $('#toolsTypeId').empty();
			 var storeHtml = "<option value=''>显示全部</option>";
			 $.each(data, function(index, row){
					storeHtml += "<option value=\""+row.id+"\"  >"+row.name+"</option>"
			 })
			 $("#toolsTypeId").html(storeHtml);
			 $("#toolsTypeId").selectpicker('refresh');
		}
	});
}

/**
 * 初始化工具柜
 */
function initToolsCabinetId() {

    $.ajax({
        cache: true,
        type: "POST",
        url: ctx + "basicData/toolsBox/initToolsCabinet",
        async: false,
    	data :{'dprtcode' : $("#dprtcode").val()},
        error: function (request) {
            $.modal.alertError("系统错误");
        },
        success: function (data) {
            $('#toolsCabinetId').empty();
            var storeHtml = "<option value=''>显示全部</option>";
            $.each(data, function (index, row) {
                storeHtml += "<option value=\"" + row.id + "\"  >" + row.boxName + "</option>"
            })
            $("#toolsCabinetId").html(storeHtml);
            $("#toolsCabinetId").selectpicker('refresh');
        }
    });

}




function localRefresh() {
    $('#notice').load(prefix + "/notReturnedNums/"+$("#dprtcode").val());
}
